package com.junzhiit.nengji.cms.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bainaeco.framework.util.DateUtil;
import com.bainaeco.framework.util.JsonUtil;
import com.junzhiit.nengji.bo.GoodsBO;
import com.junzhiit.nengji.bo.ServeTechnicianBO;
import com.junzhiit.nengji.cms.service.GoodsService;
import com.junzhiit.nengji.cms.web.exception.GoodsNotFoundException;
import com.junzhiit.nengji.cms.web.exception.GoodsStatusErrorException;
import com.junzhiit.nengji.cms.web.exception.ProfitOverflowException;
import com.junzhiit.nengji.cms.web.exception.ShopAuditFailedException;
import com.junzhiit.nengji.cms.web.exception.ShopAuditWaitException;
import com.junzhiit.nengji.cms.web.exception.ShopNotFoundException;
import com.junzhiit.nengji.cms.web.util.ViewObjectUtil;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.GoodsAddVO;
import com.junzhiit.nengji.cms.web.vo.GoodsDetailsVO;
import com.junzhiit.nengji.cms.web.vo.GoodsEditVO;
import com.junzhiit.nengji.cms.web.vo.GoodsListVO;
import com.junzhiit.nengji.cms.web.vo.GoodsVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SystemUserSessionVO;
import com.junzhiit.nengji.dao.CartDAO;
import com.junzhiit.nengji.dao.GoodsDAO;
import com.junzhiit.nengji.dao.GoodsLabelItemsDAO;
import com.junzhiit.nengji.dao.GoodsSystemTypeDAO;
import com.junzhiit.nengji.dao.GoodsTagDAO;
import com.junzhiit.nengji.dao.ModulesGoodsDAO;
import com.junzhiit.nengji.dao.ServeTechnicianDAO;
import com.junzhiit.nengji.dao.ShopChainGoodsDAO;
import com.junzhiit.nengji.dao.ShopDAO;
import com.junzhiit.nengji.dao.cache.SystemUserCacheDAO;
import com.junzhiit.nengji.dao.util.DIYKey;
import com.junzhiit.nengji.model.Goods;
import com.junzhiit.nengji.model.GoodsLabelItems;
import com.junzhiit.nengji.model.GoodsSystemType;
import com.junzhiit.nengji.model.GoodsTag;
import com.junzhiit.nengji.model.ModulesGoods;
import com.junzhiit.nengji.model.ServeTechnician;
import com.junzhiit.nengji.model.Shop;
import com.junzhiit.nengji.model.enums.GoodsStatus;
import com.junzhiit.nengji.model.enums.Is;
import com.junzhiit.nengji.model.enums.PostageType;
import com.junzhiit.nengji.model.enums.ShopIsPlatform;
import com.junzhiit.nengji.model.enums.Status;

@Service
public class GoodsServiceImpl extends BaseServiceImpl implements GoodsService {

	@Autowired
	private GoodsDAO goodsDAO;

	@Autowired
	private SystemUserCacheDAO systemUserCacheDAO;

	@Autowired
	private ShopDAO shopDAO;

	@Autowired
	private CartDAO cartDAO;
	
	@Autowired
	private ModulesGoodsDAO modulesGoodsDAO;
	
	@Autowired
	private GoodsSystemTypeDAO goodsSystemTypeDAO;
	
	@Autowired
	private ShopChainGoodsDAO shopChainGoodsDAO;
	
	@Autowired
	private GoodsLabelItemsDAO goodsLabelItemsDAO;
	
	@Autowired
	private GoodsTagDAO goodsTagDAO; 
	
	@Autowired
	private ServeTechnicianDAO serveTechnicianDAO;

	@Override
	public Map<String, Object> findPageAll(DataTablesParamVO dtp, GoodsListVO goodsListVO) {

		SystemUserSessionVO systemUserSessionVO = systemUserCacheDAO
				.getHash(DIYKey.getSessionHashKey(goodsListVO.getSessionId()), SystemUserSessionVO.class);
		Shop shop = shopDAO.query(systemUserSessionVO.getSystemId());
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}

		GoodsBO goodsBO = new GoodsBO();
		BeanUtils.copyProperties(goodsListVO, goodsBO);
		goodsBO.setShopId(shop.getId());

		List<GoodsBO> list = goodsDAO.findPageAll(goodsBO, dtp.getStart(), dtp.getLength(),shop.getIsPlatform());
		int totalCount = goodsDAO.getTotalCount(goodsBO,goodsListVO.getIsPlatform());
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO findByIdForOther(String id) {
		ResultVO result = new ResultVO();
		GoodsBO goodsBO = goodsDAO.findByIdForOther(id);
		if (goodsBO == null) {
			throw new GoodsNotFoundException("商品不存在");
		}
		result.setData(goodsBO);
		return result;
	}

	@Override
	public ResultVO findById(String id) {
		ResultVO result = new ResultVO();
		Goods goods = goodsDAO.query(id);
		if (goods == null) {
			throw new GoodsNotFoundException("商品不存在");
		}
		GoodsDetailsVO goodsDetailsVO = new GoodsDetailsVO();
		BeanUtils.copyProperties(goods, goodsDetailsVO);
		
		//system_type
		List<String> systemTypes = goodsSystemTypeDAO.getGoodsSystemTypeByGoodsId(goods.getId());
		goodsDetailsVO.setSystemTypeId(systemTypes);
		
		//technicianId
		List<ServeTechnicianBO> technicianIds = serveTechnicianDAO.findByServeId(goods.getId());
		List<String> technicianId = new ArrayList<>();
		for(int i=0;i<technicianIds.size();i++){
			technicianId.add(technicianIds.get(i).getTechnicianId());
		}
		goodsDetailsVO.setTechnicianId(technicianId);
		
		//tag
		List<String> tagIds=goodsTagDAO.getAllByGoodsId(goods.getId());
		goodsDetailsVO.setTagIds(tagIds);
		
		if (StringUtils.isNotBlank(goods.getReserveTime())) {
			String[] hours = goods.getReserveTime().split("-");
			if (hours.length >= 2) {
				goodsDetailsVO.setStartTime(hours[0]);
				goodsDetailsVO.setEndTime(hours[1]);
			}
		}
		
		result.setData(goodsDetailsVO);
		return result;
	}

	@Override
	public ResultVO add(GoodsAddVO goodsAddVO) {
		ResultVO result = new ResultVO();
		
		SystemUserSessionVO systemUserSessionVO = systemUserCacheDAO
				.getHash(DIYKey.getSessionHashKey(goodsAddVO.getSessionId()), SystemUserSessionVO.class);
		Shop shop = shopDAO.query(systemUserSessionVO.getSystemId());
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		
		//判断返利是否在范围内
		int isOpenRebate=goodsAddVO.getIsOpenRebate();
		if(isOpenRebate==1 && goodsAddVO.getProfit()<=shop.getProfit()){
			throw new ProfitOverflowException("返利值小于店铺设置的默认值");
		}

		String maxCode = goodsDAO.queryMaxCode();
		String code = Integer.toString(Integer.parseInt(maxCode) + 1);
		Integer discount = goodsAddVO.getDiscount();
		if (discount == null) {
			goodsAddVO.setDiscount(0);
		}
		goodsAddVO.setCode(code);
		goodsAddVO.setShopId(shop.getId());
		
		if(shop.getIsPlatform() == ShopIsPlatform.HEADQUARTERS.toIntStatus()){
			goodsAddVO.setStatus(GoodsStatus.AUDIT.toIntStatus());
		}
		
		if(goodsAddVO.getPostageType()==PostageType.POSTAGE.toIntValue()){
			goodsAddVO.setPostagePrice(0.00);
		}

		Goods goods = new Goods();
		BeanUtils.copyProperties(goodsAddVO, goods);
		Goods data = goodsDAO.insert(goods);

		//goodsSystemType
		if(StringUtils.isNoneBlank(data.getId())){
			List<GoodsSystemType> list = new ArrayList<GoodsSystemType>();
			for(int i = 0;i<goodsAddVO.getSystemTypeId().size();i++){
				GoodsSystemType goodsSystemType = new GoodsSystemType();
				goodsSystemType.setGoodsId(data.getId());
				goodsSystemType.setSystemTypeId(goodsAddVO.getSystemTypeId().get(i));
				goodsSystemType.setCreatedTime(new Date());
				list.add(goodsSystemType);
			}
			goodsSystemTypeDAO.batchInsert(list);
		}
		
		//goodsLabelItems
		if(StringUtils.isNotBlank(goodsAddVO.getGoodsLabelItems())){
			List<GoodsLabelItems> goodsLabelItemsList = JsonUtil.toListObject(goodsAddVO.getGoodsLabelItems(), GoodsLabelItems.class);
			for(GoodsLabelItems goodsLabelItems:goodsLabelItemsList){
				goodsLabelItems.setGoodsId(data.getId());
			}
			goodsLabelItemsDAO.batchInsert(goodsLabelItemsList);
		}
		
		//goodsTag
		if(!goodsAddVO.getTagIds().isEmpty() || goodsAddVO.getTagIds()!=null){
			List<GoodsTag> goodsTags=new ArrayList<GoodsTag>();
			for(String id:goodsAddVO.getTagIds()){
				GoodsTag goodsTag=new GoodsTag();
				goodsTag.setGoodsId(data.getId());
				goodsTag.setTagId(id);
				goodsTags.add(goodsTag);
			}
			goodsTagDAO.batchInsert(goodsTags);
		}
		
		//technicianId
		if( goodsAddVO.getTechniciansId()!=null && !goodsAddVO.getTechniciansId().isEmpty()){
			List<ServeTechnician> list=new ArrayList<ServeTechnician>();
			for(String id:goodsAddVO.getTechniciansId()){
				ServeTechnician serveTechnician=new ServeTechnician();
				serveTechnician.setShopId(data.getShopId());
				serveTechnician.setGoodsId(data.getId());
				serveTechnician.setTechnicianId(id);
				serveTechnician.setCreatedTime(new Date());
				list.add(serveTechnician);
			}
			serveTechnicianDAO.batchInsert(list);
		}
		
		result.setData(data);
		return result;
	}

	@Override
	public ResultVO edit(GoodsEditVO goodsEditVO) {

		ResultVO result = new ResultVO();
		
		SystemUserSessionVO systemUserSessionVO = systemUserCacheDAO
				.getHash(DIYKey.getSessionHashKey(goodsEditVO.getSessionId()), SystemUserSessionVO.class);
		Shop shop = shopDAO.query(systemUserSessionVO.getSystemId());
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		
		Goods goods = new Goods();
		if(goodsEditVO.getPostageType()==PostageType.POSTAGE.toIntValue()){
			goodsEditVO.setPostagePrice(0.00);
		}
		BeanUtils.copyProperties(goodsEditVO, goods);
		
		if(shop.getIsPlatform()==Is.NO.toIntValue()){
			goods.setStatus(GoodsStatus.AUDIT.toIntStatus());
		}
		
		//goodsSystemType
		if(StringUtils.isNoneBlank(goodsEditVO.getId())){
			
			goodsSystemTypeDAO.deleteByGoodsId(goodsEditVO.getId());
			
			List<GoodsSystemType> list = new ArrayList<GoodsSystemType>();
			for(int i = 0;i<goodsEditVO.getSystemTypeId().size();i++){
				GoodsSystemType goodsSystemType = new GoodsSystemType();
				goodsSystemType.setGoodsId(goodsEditVO.getId());
				goodsSystemType.setSystemTypeId(goodsEditVO.getSystemTypeId().get(i));
				goodsSystemType.setCreatedTime(new Date());
				list.add(goodsSystemType);
			}
			goodsSystemTypeDAO.batchInsert(list);
		}
		
		//technicianId
		if(goodsEditVO.getTechniciansId()!=null && !goodsEditVO.getTechniciansId().isEmpty()){
			
			serveTechnicianDAO.deleteByGoodsId(goodsEditVO.getId());
			
			List<ServeTechnician> list=new ArrayList<ServeTechnician>();
			for(String id:goodsEditVO.getTechniciansId()){
				ServeTechnician serveTechnician=new ServeTechnician();
				serveTechnician.setShopId(goods.getShopId());
				serveTechnician.setGoodsId(goodsEditVO.getId());
				serveTechnician.setTechnicianId(id);
				serveTechnician.setCreatedTime(new Date());
				list.add(serveTechnician);
			}
			serveTechnicianDAO.batchInsert(list);
		}
		
		//goodsLabelItems
		List<GoodsLabelItems> goodsLabelItemsList = JsonUtil.toListObject(goodsEditVO.getGoodsLabelItems(), GoodsLabelItems.class);
		for(GoodsLabelItems goodsLabelItems:goodsLabelItemsList){
			goodsLabelItems.setGoodsId(goods.getId());
		}
		
		GoodsLabelItems goodsLabelItems=new GoodsLabelItems();
		goodsLabelItems.setGoodsId(goods.getId());
		goodsLabelItemsDAO.deleteLabel(goodsLabelItems);
		goodsLabelItemsDAO.batchInsert(goodsLabelItemsList);
		boolean data = goodsDAO.update(goods);
		
		//goodsTag
		List<GoodsTag> goodsTags=new ArrayList<GoodsTag>();
		for(String id:goodsEditVO.getTagIds()){
			GoodsTag goodsTag=new GoodsTag();
			goodsTag.setGoodsId(goods.getId());
			goodsTag.setTagId(id);
			goodsTags.add(goodsTag);
		}
		goodsTagDAO.deleteByGoodsId(goods.getId());
		goodsTagDAO.batchInsert(goodsTags);
		
		//cart
		cartDAO.updateStatus(goodsEditVO.getId(), Status.INACTIVE.toIntStatus());
		result.setData(data);
		return result;
	}
	
	@Override
	public ResultVO batchUpdateStatus(String[] ids, Integer status,String sessionId) {
		ResultVO result = new ResultVO();
		SystemUserSessionVO systemUserSessionVO = systemUserCacheDAO
				.getHash(DIYKey.getSessionHashKey(sessionId), SystemUserSessionVO.class);
		Shop shop = shopDAO.query(systemUserSessionVO.getSystemId());
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		
		if(shop.getAuditStatus()==0){
			throw new ShopAuditWaitException("店铺等待审核中");
		}
		
		if(shop.getAuditStatus()==1){
			throw new ShopAuditFailedException("店铺审核未通过");
		}
		
		if (ids.length <= 0) {
			return result;
		}

		if (status != GoodsStatus.INACTIVE.toIntStatus() && status != GoodsStatus.ACTIVE.toIntStatus()) {
			return result;
		}
		boolean data = false;
		if (status == GoodsStatus.ACTIVE.toIntStatus()) {
			data = goodsDAO.batchUpdateStatus(ids, GoodsStatus.ACTIVE.toIntStatus());
		} else if (status == GoodsStatus.INACTIVE.toIntStatus()) {
			data = goodsDAO.batchUpdateStatus(ids, GoodsStatus.INACTIVE.toIntStatus());
		}
		result.setData(data);
		return result;
	}

	@Override
	public ResultVO updateStatus(String id, Integer status,String sessionId,String shopId) {
		ResultVO result = new ResultVO();
		String systemId=null;
		SystemUserSessionVO systemUserSessionVO=null;
		if(StringUtils.isNotBlank(shopId)){
			systemId=shopId;
		}else{			
			systemUserSessionVO = systemUserCacheDAO
					.getHash(DIYKey.getSessionHashKey(sessionId), SystemUserSessionVO.class);						
			systemId=systemUserSessionVO.getSystemId();
		}
		Shop shop = shopDAO.query(systemId);
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		
		if(shop.getAuditStatus()==0){
			throw new ShopAuditWaitException("店铺等待审核中");
		}
		
		if(shop.getAuditStatus()==1){
			throw new ShopAuditFailedException("店铺审核未通过");
		}
		
		Goods goods = goodsDAO.query(id);
		if (goods == null) {
			throw new GoodsNotFoundException("商品不存在");
		}

		if (status != GoodsStatus.ACTIVE.toIntStatus() && status != GoodsStatus.INACTIVE.toIntStatus() &&status != GoodsStatus.AUDIT.toIntStatus()) {
			return result;
		}

		boolean data = false;
		if (status == GoodsStatus.ACTIVE.toIntStatus()) {
			data = goodsDAO.updateStatus(id, GoodsStatus.ACTIVE.toIntStatus());
		} else if (status == GoodsStatus.INACTIVE.toIntStatus()) {
			data = goodsDAO.updateStatus(id, GoodsStatus.INACTIVE.toIntStatus());
			cartDAO.updateStatus(id, Status.INACTIVE.toIntStatus());
		} else if(status == GoodsStatus.AUDIT.toIntStatus()){
			data = goodsDAO.updateStatus(id, GoodsStatus.AUDIT.toIntStatus());
		}
		result.setData(data);

		return result;
	}

	@Override
	public Map<String, Object> findAll(DataTablesParamVO dtp, GoodsListVO goodsListVO) {
		GoodsBO goodsBO = new GoodsBO();
		BeanUtils.copyProperties(goodsListVO, goodsBO);
		
		if(goodsListVO.getCheckType()!=null && goodsListVO.getCheckType() == Is.YES.toIntValue()){
			SystemUserSessionVO systemUserSessionVO = systemUserCacheDAO
					.getHash(DIYKey.getSessionHashKey(goodsListVO.getSessionId()), SystemUserSessionVO.class);
			goodsBO.setChainId(systemUserSessionVO.getSystemId());
		}

		List<GoodsBO> list = goodsDAO.findPageAll(goodsBO, dtp.getStart(), dtp.getLength(),goodsListVO.getIsPlatform());
		int totalCount = goodsDAO.getTotalCount(goodsBO,goodsListVO.getIsPlatform());
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO editStatus(GoodsVO goodsVO) {
		ResultVO result = new ResultVO();
		Integer status = goodsVO.getStatus();
		if (status != GoodsStatus.AUDITSUCCESS.toIntStatus() && status != GoodsStatus.AUDITFAIL.toIntStatus()) {
			return result;
		}

		boolean data = false;
		if (status == GoodsStatus.AUDITSUCCESS.toIntStatus()) {
			data = goodsDAO.updateStatus(goodsVO.getId(), GoodsStatus.AUDITSUCCESS.toIntStatus());
		} else if (status == GoodsStatus.AUDITFAIL.toIntStatus()) {
			data = goodsDAO.updateStatus(goodsVO.getId(), GoodsStatus.AUDITFAIL.toIntStatus());
		}
		if(goodsVO.getAuditFailDescription() != null){
			Goods goods=goodsDAO.query(goodsVO.getId());
			goods.setAuditFailDescription(goodsVO.getAuditFailDescription());
			goodsDAO.update(goods);
		}
		result.setData(data);

		return result;
	}

	@Override
	public ResultVO batchEditStatus(String[] ids, Integer status,String auditFailDescription) {
		ResultVO result = new ResultVO();
		if (ids.length <= 0) {
			return result;
		}

		if (status != GoodsStatus.AUDITSUCCESS.toIntStatus() && status != GoodsStatus.AUDITFAIL.toIntStatus()) {
			return result;
		}
		boolean data = false;
		if (status == GoodsStatus.AUDITSUCCESS.toIntStatus()) {
			data = goodsDAO.batchUpdateStatus(ids, GoodsStatus.AUDITSUCCESS.toIntStatus());
		} else if (status == GoodsStatus.AUDITFAIL.toIntStatus()) {
			data = goodsDAO.batchUpdateStatus(ids, GoodsStatus.AUDITFAIL.toIntStatus());
		}
		for(int i=0;i<ids.length;i++){
			Goods goods=goodsDAO.query(ids[i]);
			goods.setAuditFailDescription(auditFailDescription);
			goodsDAO.update(goods);
		}	
		result.setData(data);
		return result;
	}

	@Override
	public Map<String, Object> goodsShopList(DataTablesParamVO dtp, String shopId,String name,Integer status,Integer type) {
		GoodsBO goodsBO = new GoodsBO();
		Shop shop = shopDAO.query(shopId);
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		goodsBO.setShopId(shopId);
		goodsBO.setName(name);
		goodsBO.setStatus(status);
		goodsBO.setType(type);
		List<GoodsBO> list = goodsDAO.findPageAll(goodsBO, dtp.getStart(), dtp.getLength(),shop.getIsPlatform());
		int totalCount = goodsDAO.getTotalCount(goodsBO,shop.getIsPlatform());
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO updateGoodsStatus(String id,String auditFailDescription) {
		ResultVO result = new ResultVO();
		Goods goods=goodsDAO.query(id);
		ModulesGoods modulesGoods=modulesGoodsDAO.query(id);
		if(goods == null){
			throw new GoodsNotFoundException("商品不存在");
		}
		
		if (goods.getStatus() != GoodsStatus.ACTIVE.toIntStatus()) {
			throw new GoodsStatusErrorException("商品不为上架状态");
		}
		if(StringUtils.isNotBlank(auditFailDescription)){
			goods.setStatus(GoodsStatus.AUDITFAIL.toIntStatus());
			goods.setAuditFailDescription(auditFailDescription);
		}
		goodsDAO.update(goods);
//		goodsDAO.updateStatus(id, GoodsStatus.AUDITFAIL.toIntStatus());
		
		if(modulesGoods != null){
			modulesGoods.setStatus(GoodsStatus.AUDITFAIL.toIntStatus());
			modulesGoodsDAO.update(modulesGoods);
		}
		
		return result;
	}
	
	@Transactional
	@Override
	public ResultVO delete(String id) {
		ResultVO result = new ResultVO();
		//商品删除
		goodsDAO.updateToDelete(id);
		
		//购物车失效
		cartDAO.updateStatus(id, Status.INACTIVE.toIntStatus());
		
		//模块商品移除
		modulesGoodsDAO.deleteByGoodsId(id);
		
		//连锁品牌商品移除
		shopChainGoodsDAO.deleteByGoodsId(id);
		
		return result;
	}

	@Override
	public ResultVO batchDeleteChainGoods(String[] ids) {
		ResultVO result=new ResultVO();
		for(String id:ids){
			delete(id);
		}
		return result;
	}
	
	
	@Override
	public Map<String, Object> findByProgram(DataTablesParamVO dtp, GoodsListVO goodsListVO){
		GoodsBO goodsBO = new GoodsBO();
		BeanUtils.copyProperties(goodsListVO, goodsBO);
		
		List<GoodsBO> list = goodsDAO.findPageAll(goodsBO, dtp.getStart(), dtp.getLength(),ShopIsPlatform.OWN.toIntStatus());
		int totalCount = goodsDAO.getTotalCount(goodsBO,ShopIsPlatform.OWN.toIntStatus());
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO getAllGoods(String sessionId,String startTime,String endTime,String fullReductionId) {
		ResultVO result=new ResultVO();
		SystemUserSessionVO systemUserSessionVO=systemUserCacheDAO.getHash(DIYKey.getSessionHashKey(sessionId), SystemUserSessionVO.class);						
		String systemId=systemUserSessionVO.getSystemId();
		Shop shop = shopDAO.query(systemId);
		if (shop == null) {
			throw new ShopNotFoundException("店铺不存在");
		}
		Date sTime=DateUtil.getDateStart(DateUtil.parseDate(startTime));
		Date eTime=DateUtil.getDateEnd(DateUtil.parseDate(endTime));
		List<Goods> goodsList=goodsDAO.getAllGoods(systemId,sTime,eTime,fullReductionId);
		result.setData(goodsList);
		return result;
	}

	@Override
	public ResultVO findByGoodsId(String serveId) {
		ResultVO result=new ResultVO();
		Goods goods = goodsDAO.query(serveId);
		GoodsBO goodsBO = new GoodsBO();
		goodsBO.setCanReserve(goods.getCanReserve());
		goodsBO.setReserveTime(goods.getReserveTime());
		goodsBO.setTime(goods.getTime());
		StringBuffer technicianName = new StringBuffer();
		List<ServeTechnicianBO> technicianNames = serveTechnicianDAO.findByServeId(serveId);
		
		for(int i=0;i<technicianNames.size();i++){
			technicianName.append(technicianNames.get(i).getTechnicianName());
			if(i<technicianNames.size()-1){
				technicianName.append("、");
			}
		}
		goodsBO.setTechnicianName(technicianName.toString());
		result.setData(goodsBO);
		return result;
	}
}
